/**
 * @Project Name:hoofungson-elk-log
 * @Package Name:cn.hoofungson.framework.elk.log.converter.pattern
 * @Since JDK 1.8
 */

package cn.hoofungson.framework.elk.log.converter.pattern;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import cn.hoofungson.framework.elk.log.constant.config.LogFieldConstants;
import cn.hoofungson.framework.elk.log.constant.config.NetworkCardConstants;
import cn.hoofungson.framework.elk.log.util.AppInfoUtils;
import cn.hoofungson.framework.elk.log.util.NetworkCardUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: HostPatternConverter
 * @Author 胡松 hoofungson@163.com
 * @Date 2020-03-07 18:28
 * @Version V1.0
 */
public class HostPatternConverter extends ClassicConverter {

    @Override
    public String convert(ILoggingEvent iLoggingEvent) {
        if (null == AppInfoUtils.getAppInfo()
                || StringUtils.isBlank(AppInfoUtils.getAppInfo().getNetCardName())
                || StringUtils.containsIgnoreCase(AppInfoUtils.getAppInfo().getNetCardName(), LogFieldConstants.PROPERTIES_DEFAULT_NULL_VALUE)) {
            return NetworkCardUtils.getHost(NetworkCardConstants.DEFAULT_NET_CARD_NAME);
        }
        String netCardName = AppInfoUtils.getAppInfo().getNetCardName();
        return NetworkCardUtils.getHost(netCardName);
    }
}
